package com.loveyukari.service;

import com.loveyukari.model.Auth;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class AuthScoreService {


    @Autowired
    private AuthService authService;
    @Autowired
    private PermissionService permissionService;

    public void addAuthScore(int authId,int addScore){
        Auth auth = authService.getCacheAuth(authId);
        authService.updateAuthScore(auth.getScore()+addScore,auth.getId());
    }

    public List<JSONObject> getAuthScoreList(){
        List<Integer> list = permissionService.getAuthIdByPermission(1);
        List<JSONObject> result = new ArrayList<>();
        for (Integer authId :
                list) {
            Auth auth = authService.getCacheAuth(authId);
            JSONObject json = new JSONObject();
            json.put("id",auth.getId());
            json.put("name",auth.getName());
            json.put("score",auth.getScore());
            result.add(json);
        }
        return result;
    }


}
